/*
 *  libKara - Library for basic instant messaging functions
 *  Copyright (C) 2007 Markus Karnik
 *
 *  This program is free software; you can redistribute it and/or modify it 
 *  under the terms of the GNU General Public License as published by the
 *  Free Software Foundation; either version 3 of the License, 
 *  or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along 
 *  with this program; if not, see <http://www.gnu.org/licenses/>.
 *  
 */

package de.karnik.libkara.proto.xmpp;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.Writer;

import de.karnik.helper.LogFunctions;

/**
 * The XMPP buffered writer class implements the buffered writer an special log functions.
 * 
 * @author Markus Karnik - markus.karnik@my-design.org
 * @version 1.0
 * @since 1.0
 */
public class XmppBufferedWriter extends BufferedWriter {

	/**
	 * Constructs a XMPP buffered writer.
	 * 
	 * @param out The writer object to use.
	 */
	public XmppBufferedWriter( Writer out ) {
		super( out, 8 );
	}
	
	/* (non-Javadoc)
	 * @see java.io.Writer#write(java.lang.String)
	 */
	@Override
	public void write( String data ) throws IOException {
		
		if( LogFunctions.DEBUG && LogFunctions.logLevel == LogFunctions.LOG_LEVEL_3 ) {
			StringBuffer sb = new StringBuffer();
			sb.append( "OUT ~~~> " );
			sb.append( data );
			LogFunctions.log( sb.toString() );
		}
		
		super.write( data );
	}
}